﻿using System;
using System.Collections.Generic;
using System.Linq;
using csvm.coordinator.contract;
using csvm.datamodel.contract;
using csvm.fileadapter.contract;
using csvm.pagebuilder.contract;
using csvm.recordbuilder.contract;

namespace Coordinator.Tests {

    internal class MyFileAdapter : IFileAdapter {
        public IEnumerable<string> ReadFile(string filename) {
            return new[] { "Header", "Zeile1" , filename };
        }

        public event Action<double> OnProgressChanged;

        public void ThrowEvent(double value) {
            if (OnProgressChanged != null) {
                OnProgressChanged(value);
            }
        }
    }

    internal class MyRecordBuilder : IRecordBuilder {
        public IEnumerable<Record> BuildRecords(IEnumerable<string> lines) {
            return lines.Select(line => new Record(line.Split(';')));
        }
    }

    internal class MyPageBuilder : IPageBuilder {
        public IEnumerable<Page> BuildPages(IEnumerable<Record> records) {
            var page = new Page(records);
            yield return page;
        }
    }

    internal class Subscriber {

        private readonly ICoordinator coordinator;
        internal double ResultAfterProgressChanged { get; set; }

        internal Subscriber(ICoordinator coordinator) {
            this.coordinator = coordinator;
            this.coordinator.OnProgressChanged += value => ResultAfterProgressChanged = value;
        }
    }

}
